import { getAreaObj } from '@/utils/util'
import { configToSearch, toSearchHandle } from '@/views/datacenter/business/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		// { label: '设施唯一值', prop: 'soleValue' },

		{ label: '评定对象', prop: 'name' },
		{ label: '所属地区', prop: 'tableAreaName', width: 220 },

		{
			label: '评定时间',
			prop: 'assessmentTime',
		},
		{
			label: '评定结果',
			prop: 'assessmentResult',
			propName: 'assessmentResultLabel',
			code: 'ASSESSMENT_RESULT',
			api: 'getDictItemList',
			type: 'remoteSelect',
		},
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0, type: 'danger' },
				{ label: '是', value: 1, type: 'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}

export const formConfig = {
	label: '基础信息',
	prop: 'dp_service_object',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	column: [
		// 等级评定机构基础档案
		{
			type: 'DividerHtml',
			custome: 'divider',
			position: 'center',
			modelValue: '等级评定设施基础档案',
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '等级评定设施基础档案',
			span: 24,
		},
		{
			label: '唯一值',
			prop: 'soleValue',
			type: 'input',
			span: 8,
		},
		{
			label: '组织名称',
			prop: 'name',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入组织名称' }],
		},
		{
			label: '机构统一社会信用代码',
			prop: 'creditCode',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构统一社会信用代码' }],
		},
		{
			label: '机构地址',
			prop: 'address',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入机构地址' }],
		},
		{
			label: '法定代表人姓名',
			prop: 'legalRepName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人姓名' }],
		},
		{
			label: '法定代表人联系电话',
			prop: 'legalRepContact',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入法定代表人联系电话' }],
		},
		{
			label: '是否建设完成',
			prop: 'buildCompleted',
			propName: 'buildCompletedLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
			rules: [{ required: true, message: '请选择是否建设完成' }],
		},
		{
			label: '组织使用面积',
			prop: 'usageArea',
			type: 'text',
			append: '平方米',
			span: 8,
			rules: [{ required: true, message: '请填写组织使用面积' }],
		},
		{
			label: '房产证或租赁合同',
			prop: 'contract',
			type: 'upload',
			labelPosition: 'top',
			showFileList: true,
			limit: 9,
			multiple: false,
			span: 24,
			rules: [{ required: true, message: '请上传房产证或租赁合同' }],
		},

		// 评估档案
		{
			type: 'DividerHtml',
			custome: 'divider',
			position: 'center',
			modelValue: '评定档案',
			span: 24,
		},
		{
			type: 'DividerHtml',
			modelValue: '评定档案',
			span: 24,
		},

		{
			label: '申报等级',
			prop: 'declareLevel',
			propName: 'declareLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择申报等级' }],
		},
		{
			label: '申报时间',
			prop: 'declareTime',
			type: 'date',
			changeField: true,
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择申报时间' }],
		},
		{
			label: '总体要求',
			prop: 'overallRequir',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写总体要求' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '资质条件',
			prop: 'qualificationCond',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写资质条件' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '基本职能',
			prop: 'basicFunction',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写基本职能' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '服务项目',
			prop: 'serviceItem',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写服务项目' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '服务绩效',
			prop: 'servicePerformance',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写服务绩效' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '安全保障',
			prop: 'securityGuarantee',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写安全保障' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '基础设施',
			prop: 'infrastructure',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写基础设施' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '人员配备',
			prop: 'staffing',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写人员配备' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '规章制度',
			prop: 'regulations',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写规章制度' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '监督管理',
			prop: 'supervisionManagement',
			type: 'text',
			append: '分',
			span: 8,
			rules: [
				{ required: true, message: '请填写监督管理' },
				{ pattern: /^[0-9]*$/, message: '请输入正确的评分' },
			],
		},
		{
			label: '评定时间',
			prop: 'assessmentTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 8,
			rules: [{ required: true, message: '请选择评定时间' }],
		},
		{
			label: '评定等级',
			prop: 'assessmentLevel',
			propName: 'assessmentLevelLabel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择评定等级' }],
		},
		{
			label: '评定结果',
			prop: 'assessmentResult',
			propName: 'assessmentResultLabel',
			code: 'ASSESSMENT_RESULT',
			api: 'getDictItemList',
			type: 'remoteSelect',
			filterKey: 'value',
			multiple: false,
			changeField: true,
			span: 8,
			rules: [{ required: true, message: '请选择评定结果' }],
		},
		{
			label: '不合格原因',
			prop: 'unqualifiedReason',
			type: 'textarea',
			span: 24,
		},
		{
			label: '专业支撑',
			prop: 'professionalSupport',
			propName: 'professionalSupportLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
		},
		{
			label: '养老志愿服务',
			prop: 'volunteerService',
			propName: 'volunteerServiceLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
		},
		{
			label: '医养结合',
			prop: 'medicalCare',
			propName: 'medicalCareLabel',
			type: 'remoteSelect',
			code: 'COMMON_FLAG',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			changeField: false,
			span: 8,
		},
	],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(formConfig.column)],
}
const handle = (config) => {
	let column = JSON.parse(JSON.stringify(config.column))
	column.forEach((el, index) => {
		if (el.custome == 'divider') {
			column.splice(index, 1)
		}
		if (el.type != 'DividerHtml') {
			el.span = 8
		}
	})
	return column
}
export const detailConfig = {
	label: '查看档案',
	prop: 'dp_service_object',
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	// column: handle(formConfig),
	column: formConfig.column,
}

export const baseConfig = {
	pageName: '养老设施等级评定',
	dictcodes: ['ASSESSMENT_RESULT', 'ORG_LEVEL', 'ORG_TYPE', 'COMMON_FLAG'],
	rowKey: 'id',
	addLabel: '添加',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	api: {
		moreSearch: 'view_dpServiceFacilitiesLevelEvaluate_search',
		add: 'view_dpServiceFacilitiesLevelEvaluate_add',
		edit: 'view_dpServiceFacilitiesLevelEvaluate_edit',
		index: 'view_dpServiceFacilitiesLevelEvaluate_page',
		delete: 'view_dpServiceFacilitiesLevelEvaluate_del',
		export: 'view_dpServiceFacilitiesLevelEvaluate_export',
		import: 'view_dpServiceFacilitiesLevelEvaluate_import',
	},
	paramsObj: {
		code: 3201,
	},
	auth: {
		// add: 'view_dpServiceFacilitiesLevelEvaluate_add',
		index: 'view_dpServiceFacilitiesLevelEvaluate_page',
		// edit: 'view_dpServiceFacilitiesLevelEvaluate_edit',
		delete: 'view_dpServiceFacilitiesLevelEvaluate_del',
		mulitSet: 'mulitSet',
		// export: 'view_dpServiceFacilitiesLevelEvaluate_export',
		// import: 'view_dpServiceFacilitiesLevelEvaluate_import',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'detail',
			auth: '',
			text: true,
			show: true,
		},
		// {
		// 	icon: 'editor',
		// 	label: '编辑',
		// 	type: 'primary',
		// 	operate: 'edit',
		// 	auth: 'view_dpServiceFacilitiesLevelEvaluate_edit',
		// 	text: true,
		// 	show: true,
		// },
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '设施唯一值',
				prop: 'soleValue',
				span: 6,
			},
			{
				label: '评定对象',
				prop: 'name',
				span: 6,
			},
			{
				label: '设施所属地区',
				propName: 'areas_name',
				type: 'AplidAreaSelect',
				span: 6,
			},
			{
				label: '评定时间',
				prop: 'assessmentTime',
				type: 'date',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 6,
			},
			{
				label: '评定结果',
				prop: 'assessmentResult',
				propName: 'assessmentResultLabel',
				code: 'ASSESSMENT_RESULT',
				api: 'getDictItemList',
				type: 'remoteSelect',
				filterKey: 'value',
				multiple: false,
				span: 6,
			},
		],
	},

	tableConfig,
	detailConfig,
	formConfig,
	beforeOnLoadFormate: async (params) => {
		const areasNameObj = getAreaObj(params.areas_name, 'belong')
		// 全字段搜索
		params = toSearchHandle(moreSearchConfig, {}, params)
		return Promise.resolve({
			...params,
			...areasNameObj,
			areas_name: undefined, // 户籍区域
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areas_name = getAreaObj(item, 'belong')
			return {
				...item,
				areas_name,
				tableAreaName: [item.belongAreaName, item.belongStreetName, item.belongCommunityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
